package org.example;

import cn.clj1.cell.CljCell;
import cn.clj1.*;
import org.junit.Test;
import java.util.Hashtable;

public class MyClojureEval_case_1 {
    public static MyClojureReader getReader(String txt)
    {
        CljLinesFromString myIInput = new CljLinesFromString(txt);
        CljCharIterator myCharIterator = new CljCharIterator(myIInput);
        CljLexer lexer = new CljLexer(myCharIterator);
        MyClojureReader myLispReader = new MyClojureReader(lexer);
        return myLispReader;
    }

    @Test
    public void test_let() throws Exception {

        MyClojureInterp myClojureInterp = new MyClojureInterp();
        MyClojureReader myLispReader = getReader("(let [a 1 b 2] \n" +
                "         (+ a b))");
        CljCell myCell = myLispReader.getExpression();

        System.out.println(myCell.toString());
        CljCell cell = myClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
        System.out.println(cell.toString());
    }

    @Test
    public void test_loop() throws Exception {

        MyClojureInterp myClojureInterp = new MyClojureInterp();
        MyClojureReader myLispReader = getReader("(loop [iter 1\n" +
                "       acc  0]\n" +
                "  (if (> iter 10)\n" +
                "    (println acc)\n" +
                "    (recur (+ 1 iter) (+ acc iter))))");
        CljCell myCell = myLispReader.getExpression();
        //System.out.println(myCell.toString());
        myClojureInterp.eval(myCell, new Hashtable<String, CljCell>(), null, new CljCell());
    }
}









































